<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/axios.min.js"></script>
    <script>
      function $(id) {
       return document.getElementById(id)
      }
      function getQuery(variable)
      {
          var query = window.location.search.substring(1);
          var vars = query.split("&");
          for (var i=0;i<vars.length;i++) {
              var pair = vars[i].split("=");
              if(pair[0] == variable){return pair[1];}
          }
          return(false);
      }
      window.onload = function () {
          axios.get("/user/getUserSession").then(resp =>{
              if(resp.data == ""){
                  $("indexSpan").innerHTML="你好，请重新登录"+"<a href='/html/login.html'>登陆</a>"
              }
              else {
                  $("userId").value = resp.data.id
                  $("img").src ="/html/img/"+resp.data.img
                  $("nameSpan").innerHTML = resp.data.name
                  $("dateSpan").innerHTML = resp.data.inDate
              }
          });
      }
      function postContent() {
         axios.get("/post/add",{
             params:{
                 userId:$("userId").value,
                 mainId:getQuery("id"),
                 title:$("postTitle").value,
                 content:$("content").value
             }
         }).then(resp =>{
             if(resp.data == "ok"){
               var number =  getQuery("number")+1

                 location.href="/html/main.html"
             }
         });

      }
    </script>
</head>
<body>
     <input type="hidden" id="userId">
     头像:<img id="img" style="width: 50px;height:50px"><br>
     楼主:<span id="nameSpan"></span><br>
     注册日期:<span id="dateSpan"></span><br>
     标题:<input type="text" id="postTitle"><br>
     内容:<input type="text" id="content" style="width: 100px;height: 100px"><br>
     <input type="button" value="回帖" onclick="postContent()">
</body>
</html>